<?php
namespace ImiDemo\HttpDemo\MainServer\Model;

use Imi\Model\Model;
use Imi\Model\Annotation\Table;
use Imi\Model\Annotation\Column;
use Imi\Model\Annotation\Entity;
use Imi\Model\Annotation\Relation\JoinTo;
use Imi\Model\Annotation\Relation\AutoSave;
use Imi\Model\Annotation\Relation\JoinFrom;
use Imi\Model\Annotation\Relation\OneToOne;
use Imi\Model\Annotation\Relation\OneToMany;
use Imi\Model\Annotation\Relation\PolymorphicOneToOne;
use Imi\Model\Annotation\Relation\AutoDelete;
use Imi\Model\Annotation\Relation\AutoInsert;
use Imi\Model\Annotation\Relation\AutoUpdate;
use Imi\Model\Annotation\Relation\ManyToMany;
use Imi\Model\Annotation\Relation\JoinToMiddle;
use Imi\Model\Annotation\Relation\JoinFromMiddle;

/**
 * User
 * @Entity
 * @Table(name="tb_user", id={"id"})
 * @property int $id
 * @property string $username
 * @property \ImiDemo\HttpDemo\MainServer\Model\UserEx $ex
 * @property \Imi\Util\ArrayList $userRole
 * @property \Imi\Util\ArrayList $role
 * @property \ImiDemo\HttpDemo\MainServer\Model\Avatar $avatar
 */
class User extends Model
{
    /**
     * @OneToOne("UserEx")
     * @JoinFrom("id")
     * @JoinTo("user_id")
     * @AutoSave(true)
     * @AutoDelete
     *
     * @var \ImiDemo\HttpDemo\MainServer\Model\UserEx
     */
    protected $ex;

    /**
     * Get the value of ex
     *
     * @return  \ImiDemo\HttpDemo\MainServer\Model\UserEx
     */ 
    public function getEx()
    {
        return $this->ex;
    }

    /**
     * Set the value of ex
     *
     * @param  \ImiDemo\HttpDemo\MainServer\Model\UserEx  $ex
     *
     * @return  self
     */ 
    public function setEx(\ImiDemo\HttpDemo\MainServer\Model\UserEx $ex)
    {
        $this->ex = $ex;

        return $this;
    }

    /**
     * @ManyToMany(model="Role", middle="UserRole", rightMany="role")
     * @JoinToMiddle(field="id", middleField="user_id")
     * @JoinFromMiddle(middleField="role_id", field="id")
     * 
     * @AutoInsert
     * @AutoUpdate(orphanRemoval=true)
     * @AutoSave(orphanRemoval=true)
     * @AutoDelete
     *
     * @var \Imi\Util\ArrayList
     */
    protected $userRole;
    
    /**
     * Get the value of userRole
     *
     * @return  \Imi\Util\ArrayList
     */ 
    public function getUserRole()
    {
        return $this->userRole;
    }

    /**
     * Set the value of userRole
     *
     * @param  \Imi\Util\ArrayList  $userRole
     *
     * @return  self
     */ 
    public function setUserRole($userRole)
    {
        $this->userRole = $userRole;

        return $this;
    }

    /**
     * 
     *
     * @var \Imi\Util\ArrayList
     */
    protected $role;

    /**
     * Get the value of role
     *
     * @return  \ImiDemo\HttpDemo\MainServer\Model\ArrayList[]
     */ 
    public function getRole()
    {
        return $this->role;
    }

    /**
     * Set the value of role
     *
     * @param  \ImiDemo\HttpDemo\MainServer\Model\ArrayList[]  $role
     *
     * @return  self
     */ 
    public function setRole($role)
    {
        $this->role = $role;

        return $this;
    }

    /**
     * 头像
     * 
     * @PolymorphicOneToOne(model=ImiDemo\HttpDemo\MainServer\Model\Avatar::class, type="type", typeValue=1)
     * @JoinTo("relation_id")
     * @AutoSave
     * @AutoDelete
     *
     * @var \ImiDemo\HttpDemo\MainServer\Model\Avatar
     */
    protected $avatar;

    /**
     * Get 头像
     *
     * @return  \ImiDemo\HttpDemo\MainServer\Model\Avatar
     */ 
    public function getAvatar()
    {
        return $this->avatar;
    }

    /**
     * Set 头像
     *
     * @param  \ImiDemo\HttpDemo\MainServer\Model\Avatar  $avatar  头像
     *
     * @return  self
     */ 
    public function setAvatar(\ImiDemo\HttpDemo\MainServer\Model\Avatar $avatar)
    {
        $this->avatar = $avatar;

        return $this;
    }

    /**
     * id
     * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true)
     * @var int
     */
    protected $id;

    /**
     * 获取 id
     *
     * @return int
     */ 
    public function getId()
    {
        return $this->id;
    }

    /**
     * 赋值 id
     * @param int $id id
     * @return static
     */ 
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

    /**
     * username
     * @Column(name="username", type="varchar", length=32, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false)
     * @var string
     */
    protected $username;

    /**
     * 获取 username
     *
     * @return string
     */ 
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * 赋值 username
     * @param string $username username
     * @return static
     */ 
    public function setUsername($username)
    {
        $this->username = $username;
        return $this;
    }

}